package com.cn.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.dsna.util.images.ValidateCode;

public class ValidateCodeServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ValidateCode vc = new ValidateCode(120,70,4,2);//(长，宽，字符串长度，干扰线数量)
		//String code = vc.getCode();//获得正确答案
		//vc.write("e://hha.jpg");//流（可以写到网页中），path（写到硬盘中）
		vc.write(response.getOutputStream());
		request.getSession().setAttribute("code", vc.getCode());
	}

}
